﻿
package extremefx.crypto {

	/**
	 * @author Marcelo Volmaro
	 */
	public class Random {
		public static function text(newLength:uint = 1, userAlphabet:String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"):String {
			var alphabet:Array = userAlphabet.split("");
			var alphabetLength:int = alphabet.length;
			var randomLetters:String = "";
			for (var i:uint = 0; i < newLength; i++){
				randomLetters += alphabet[int(Math.floor(Math.random() * alphabetLength))];
			}
			
			return randomLetters;
		}
		
		public static function UUID():String {
			return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, 
				function(c:String):String {
        			var r:Number = Math.random() * 16 | 0;
        			var v:Number = (c == 'x') ? r : (r & 0x3 | 0x8);
            		return v.toString(16);
  			}).toUpperCase();
		}
	}
}
